package pl.radiomaryja.softcognito;

import java.util.List;

import org.softcognito.webcontent.radiomaryja.CategoryDTO;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class AdapterCategories  extends ArrayAdapter<CategoryDTO>{

	    Context context;
	    int layoutResourceId;   
	    List<CategoryDTO> data = null;
	   
	    public AdapterCategories(Context context, int layoutResourceId, List<CategoryDTO> cl) {
	        super(context, layoutResourceId, cl);
	        this.layoutResourceId = layoutResourceId;
	        this.context = context;
	        this.data = cl;
	    }

	    @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        View row = convertView;
	        CategoryHolder holder = null;
	       
	        if(row == null)
	        {
	            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
	            row = inflater.inflate(layoutResourceId, parent, false);
	           
	            holder = new CategoryHolder();
	            holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
	           
	            row.setTag(holder);
	        }
	        else
	        {
	            holder = (CategoryHolder)row.getTag();
	        }
	       
	        CategoryDTO cat = data.get(position);
	        holder.txtTitle.setText(cat.getCategoryName());
	       
	        return row;
	    }
	   
	    static class CategoryHolder
	    {
	        TextView txtTitle;
	    }
	}
